package com.huacloud.rocketmq;

import java.io.*;
import java.util.Date;
import java.util.Properties;
import org.apache.log4j.*;

/**
 * Created by hcf on 2017/6/16.
 */
public class ProducerMain {

    private static Logger log = Logger.getLogger(ProducerMain.class);

    public static void main(String[] args) {
        String mqGroupName = "GroupTest1";
        String mqNamesrvIp ="127.0.0.1";
        String mqNamesrvPort = "9876";
        String mqProducerInstance="Prod_instances_1";
        String mqTopicName = "TopicTest1";
        String mqTagName = "TageTest";

        try {
            InputStream io = ProducerMain.class.getResourceAsStream("/MQProducerConfig.properties");
            Properties prop = Properties.class.newInstance();
            prop.load(io);
            mqGroupName = prop.getProperty("MQ_PRODUCER_GROUP_NAME");
            //log.info(mqGroupName);
            mqNamesrvIp = prop.getProperty("MQ_NAMESRV_IP");
            //log.info(mqNamesrvIp);
            mqNamesrvPort = prop.getProperty("MQ_NAMESRV_PORT");
            //log.info(mqNamesrvPort);
            mqProducerInstance = prop.getProperty("MQ_PRODUCER_INSTANCE");
            mqTopicName = prop.getProperty("MQ_TOPIC_NAME");
            mqTagName = prop.getProperty("MQ_TAG_NAME");

        } catch (IOException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

        SyncProducer sp = new SyncProducer(mqGroupName,mqNamesrvIp,mqNamesrvPort,mqProducerInstance,mqTopicName,mqTagName);
        log.info(sp.toString());

        sp.sendMessage("MQ of RocketMQ send message at "+new Date());
    }
}
